// pages/childattendanceday/childattendanceday.js
const app = getApp()
var util = require("../../utils/util.js");
const MONTHS = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'June.', 'July.', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.'];
const qiniuUploader = require("../../utils/qiniuUploader");
var utils = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    qiniuToken: "",
    active: 0,
    activeqiandao: 0,
    activeqiantui: 0,
    classid: 0,
    classlist: [],
    selectdate: util.formatDate(new Date()),
    selectdateqiantui: util.formatDate(new Date()),
    currentdate: util.formatDate(new Date()),
    enddate: util.formatDate(new Date()),
    startdate: util.formatDateMonth(new Date('2000-01-01')),
    attendanceKidListByMonthno: [],
    attendanceKidListByMonthyes: [],
    leaveListByMonthyes: [],
    allkidcount: 0,
    inkidcount: 0,
    leavecountno: 0,
    leavekidcount: 0,
    weidaokidcount: 0,
    attendanceKidListByMonthnoqiantui: [],
    attendanceKidListByMonthyesqiantui: [],
    leaveListByMonthyesqiantui: [],
    allkidcountqiantui: 0,
    leavekidcountqiantui: 0,
    nooutkidCountqiantui: 0,
    outkidCountqiantui: 0,
    photoList: [],
    photourl:[],
  },
  onclasschange({
    detail
  }) {
    this.setData({
      classid: detail
    });
    if (this.data.active == 0) {
      this.queryData()
    } else {
      this.queryQituiData();
    }

  },
  onChange(event) {
    console.log("event================" + event.detail.index)
    this.setData({
      active: event.detail.index
    })
    if (event.detail.index == 0) {
      this.queryData();
    } else {
      this.queryQituiData();
    }
   

  },
  qiandaoonChange(event) {
    console.log("event================" + event.detail.index)
    this.setData({
      activeqiandao: event.detail.index
    })

  },
  qiantuionChange(event) {
    console.log("event================" + event.detail.index)
    this.setData({
      activeqiantui: event.detail.index
    })

  },
  weiqianhandleClick: function (e) {
    //console.log("endTime - startTime = " + (this.endTime - this.startTime));   
    var index = e.currentTarget.dataset.index;
    var arr = this.data.attendanceKidListByMonthno;
    var obj = this.data.attendanceKidListByMonthno[index]
    if (obj.status == 0) {
      obj.status = 1
    } else {
      obj.status = 0
    }
    arr[index] = obj
    this.setData({
      attendanceKidListByMonthno: arr
    })
    console.log("点击");

  },

  weiqianhandleLongPress: function (e) {
    //console.log("endTime - startTime = " + (this.endTime - this.startTime));
    var index = e.currentTarget.dataset.index;
    var relationship = this.data.attendanceKidListByMonthno[index].relationshipList
    var nameList = [];
    var phone = [];
    for (var i = 0; i < relationship.length; i++) {
      nameList.push(relationship[i].name)
      phone.push(relationship[i].mobile)
    }
    wx.showActionSheet({
      itemList: nameList,
      success: function (res) {
        console.log(res.tapIndex)
        wx.makePhoneCall({
          phoneNumber: phone[res.tapIndex],
        })
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
    console.log("长按");
  },

  //请假
  weiqianqingjiaClick: function (e) {
    console.log(e);
    var that = this
    var nameList = ["事假", "病假"];
    var arr = this.data.attendanceKidListByMonthno;
    var kidStr = ""
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].status == 1) {
        kidStr += "," + arr[i].UserID
      }
    }
    if (kidStr.length > 0) {
      kidStr = kidStr.substring(1)
      wx.showActionSheet({
        itemList: nameList,
        success: function (res) {
          console.log(res.tapIndex)
          var leaveType = parseInt(res.tapIndex) + 1
          that.setLeave(kidStr, leaveType)
        },
        fail: function (res) {
          console.log(res.errMsg)
        }
      })
    } else {
      wx.showToast({
        title: '请选择请假的学生',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    }
  },

  //补签
  weiqianbuqianClick: function (e) {
    console.log(e);
    var that = this
    var arr = this.data.attendanceKidListByMonthno;
    var kidStr = ""
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].status == 1) {
        kidStr += "," + arr[i].UserID
      }
    }
    if (kidStr.length > 0) {
      kidStr = kidStr.substring(1)
      wx.chooseImage({
        count: 1, // 默认最多上传1张
        sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: [ 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success(res) {
          var tempFilePaths = res.tempFilePaths; // 返回选定照片的本地路径列表 
          that.setData({
            photoList:tempFilePaths
          })
          console.log(that.data.photoList)
          //上传图片，补签
          that.sendImge(kidStr,1,0);  
        }
      })
    } else {
      wx.showToast({
        title: '请选择补签的学生',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    }
    console.log("点击");

  },

  //签退
  weiqiantuiqiantuiClick: function (e) {
    console.log(e);
    var that = this
    var arr = this.data.attendanceKidListByMonthnoqiantui;
    var kidStr = ""
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].status == 1) {
        kidStr += "," + arr[i].UserID
      }
    }
    if (kidStr.length > 0) {
      kidStr = kidStr.substring(1)
      wx.chooseImage({
        count: 1, // 默认最多上传1张
        sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success(res) {
          var tempFilePaths = res.tempFilePaths; // 返回选定照片的本地路径列表 
          that.setData({
            photoList:tempFilePaths
          })
          console.log(that.data.photoList)
          //上传图片，补签
          that.sendImge(kidStr,2,0);  
        }
      })
    } else {
      wx.showToast({
        title: '请选择签退的学生',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    }
    console.log("点击");

  },

  //请假中的补签
  qingjiabuqianClick: function (e) {
    console.log(e);
    var that = this
    var index = e.currentTarget.dataset.index;
    var kidStr = this.data.leaveListByMonthyes[index].userID
      wx.chooseImage({
        count: 1, // 默认最多上传1张
        sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
        success(res) {
          var tempFilePaths = res.tempFilePaths; // 返回选定照片的本地路径列表 
          that.setData({
            photoList:tempFilePaths
          })
          console.log(that.data.photoList)
          //上传图片，补签
          that.sendImge(kidStr,1,1);  
        }
      })
   
    console.log("点击");

  },

  qingjiaqiantuibuqianClick: function (e) {
    console.log(e);
    var that = this
    var index = e.currentTarget.dataset.index;
    var kidStr = this.data.leaveListByMonthyesqiantui[index].userID
      wx.chooseImage({
        count: 1, // 默认最多上传1张
        sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
        success(res) {
          var tempFilePaths = res.tempFilePaths; // 返回选定照片的本地路径列表 
          that.setData({
            photoList:tempFilePaths
          })
          console.log(that.data.photoList)
          //上传图片，补签
          that.sendImge(kidStr,1,1);  
        }
      })
   
    console.log("点击");

  },

  //已签请假
  yiqianqingjiaClick: function (e) {
    console.log(e);
    var that = this
    var nameList = ["事假", "病假"];
    var arr = this.data.attendanceKidListByMonthyes;
    var kidStr = ""
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].status == 1) {
        kidStr += "," + arr[i].UserID
      }
    }
    if (kidStr.length > 0) {
      kidStr = kidStr.substring(1)
      wx.showActionSheet({
        itemList: nameList,
        success: function (res) {
          console.log(res.tapIndex)
          var leaveType = parseInt(res.tapIndex) + 1
          that.setLeave(kidStr, leaveType)
        },
        fail: function (res) {
          console.log(res.errMsg)
        }
      })
    } else {
      wx.showToast({
        title: '请选择请假的学生',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    }
  },

  //已签撤回
  yiqianchehuiClick: function (e) {
    console.log(e);
    var that = this
    var arr = this.data.attendanceKidListByMonthyes;
    var kidStr = ""
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].status == 1) {
        kidStr += "," + arr[i].UserID
      }
    }
    if (kidStr.length > 0) {
      var status = 1
      kidStr = kidStr.substring(1)
      that.setWithdraw(kidStr, status)
    } else {
      wx.showToast({
        title: '请选择撤回的学生',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    }
  },



  yiqianhandleClick: function (e) {
    var index = e.currentTarget.dataset.index;
    var kidid = this.data.attendanceKidListByMonthyes[index].UserID
    var kidname= this.data.attendanceKidListByMonthyes[index].Name
    //打开
    console.log("点击");
    wx.navigateTo({
      url: '../childattendancedetail/childattendancedetail?kidid='+kidid+"&kidname="+kidname
    })
  },

  yiqiantuihandleClick: function (e) {

    var index = e.currentTarget.dataset.index;
    var kidid = this.data.attendanceKidListByMonthyesqiantui[index].UserID
    var kidname= this.data.attendanceKidListByMonthyesqiantui[index].Name
    //打开
    wx.navigateTo({
      url: '../childattendancedetail/childattendancedetail?kidid='+kidid+"&kidname="+kidname
    })
  },


  weiqiantuidaijieClick: function (e) {

    console.log(e);
    var that = this
    var arr = this.data.attendanceKidListByMonthnoqiantui;
    var index = -1
    var count=0;
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].status == 1) {
        index=i
        count++
      }
    }
    if (count > 0) {
      if(count>1){
        wx.showToast({
          title: '只能选择一个待接的学生',
          icon: 'none',
          duration: 1000,
          mask: true
        })
      }
      else{
        var mess = JSON.stringify(this.data.attendanceKidListByMonthnoqiantui[index])
        //打开
        wx.navigateTo({
          url: '../childattendancedaijie/childattendancedaijie?mess='+mess
        })
      }
    
    } else {
      wx.showToast({
        title: '请选择一个待接的学生',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    }
    console.log("点击");
    
  },


  yiqianhandleLongPress: function (e) {
    var index = e.currentTarget.dataset.index;
    var arr = this.data.attendanceKidListByMonthyes;
    var obj = this.data.attendanceKidListByMonthyes[index]
    if (obj.status == 0) {
      obj.status = 1
    } else {
      obj.status = 0
    }
    arr[index] = obj
    this.setData({
      attendanceKidListByMonthyes: arr
    })
    console.log("长按");
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var list = wx.getStorageSync('classlist');
    var classlist = []
    var classobj = {
      text: "全部班级每日详情",
      value: 0
    }
    classlist.push(classobj)
    for (var i = 0; i < list.length; i++) {
      var classobj = {
        text: list[i].className + "每日详情",
        value: list[i].classID
      }
      classlist.push(classobj)
    }
    this.setData({
      classid: classlist[0].value,
      classlist: classlist
    })

    this.getQiniuToken()

    
  },

  //请假
  setLeave: function (kididstr, leaveType) {
    var that = this;
    var data = {
      "userid": app.globalData.userId,
      "schoolid": app.globalData.schoolId,
      "kididstr": kididstr,
      "leaveType": leaveType,
      "appType": app.globalData.appType,
      "appKey": app.globalData.appKey,
      "timeSpan": app.globalData.timespan,
      "mobileType": app.globalData.mobileType,
      "mobileSerialnumber": ""
    }
    wx.request({
      url: app.globalData.serverUrl,
      data: {
        "data": JSON.stringify(data),
        'act': "send_leaveforkids"
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success: function (res) {
        console.log(res);
        if (res.data.status == 0) {
          wx.showToast({
            title: '请假成功',
            icon: 'none',
            duration: 1000,
            mask: true
          })
          if (that.data.active == 0) {
            that.queryData()
          } else {
            that.queryQituiData();
          }
        } else {
          wx.showToast({
            title: '请假失败',
            icon: 'none',
            duration: 1000,
            mask: true
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '请假失败',
          icon: 'none',
          duration: 1000,
          mask: true
        })
      },
      complete: function (res) {
        console.log('submit complete');
      }
    })
  },

  sendImge: function(kididstr, status, leaveType) { 
    wx.showNavigationBarLoading()					//在当前页面显示导航条加载动画
    wx.showLoading({								//显示 loading 提示框
      title: "处理中...",
    })
    var count=0;
    for(var i=0;i<this.data.photoList.length;i++){
      var timestamp = Date.parse(new Date());
      timestamp = timestamp / 1000;
      var _this = this
      var filepath=this.data.photoList[i]
      // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片  
      qiniuUploader.upload(filepath, res => {
       console.log(res)
       var url=res.imageURL
      //  var pathList=_this.data.photourl;
      //  pathList.push(url)
      //  _this.setData({
      //  //注意这中间有个"/"在这上面耽误了半个小时
      //  photourl:pathList
      //  })
      //  count++;
      //  if(count==_this.data.photoList.length){
      //   _this.setbuqian(kididstr, status, leaveType, punchphotoid, punchphoto)
      //  }
      _this.setbuqian(kididstr, status, leaveType, 0, url)
      
     }, (error) => {
      wx.hideNavigationBarLoading()
      wx.hideLoading()
      wx.showToast({
        title: "操作失败",
        icon: 'none',
        duration: 1000,
        mask: true
      })
      return;
     }, {
       key: "jygy/" + "photo/" + app.globalData.schoolId + "/" + app.globalData.classid + "/" + timestamp + "/" + utils.formatDate(new Date()) + utils.wxuuid() + ".jpg",
         region: 'NCN',
         uptoken: _this.data.qiniuToken,
         uploadURL: 'https://up-z1.qbox.me',
         domain: app.globalData.qiniurUrl,
     })
    }

  },
    
    
  //补签和签退
  setbuqian: function(kididstr, status, leaveType, punchphotoid, punchphoto) {
    var that = this;
    var data = {
      "userid": app.globalData.userId,
      "schoolid": app.globalData.schoolId,
      "kididstr": kididstr,
      "status": status, ///1入园   2离园
      "leaveType": leaveType, //1请假   2其他
      "punchphotoid": punchphotoid,
      "punchphoto": punchphoto,
      "appType": app.globalData.appType,
      "appKey": app.globalData.appKey,
      "mobileType": app.globalData.mobileType,
      "timeSpan": app.globalData.timespan,
      "mobileSerialnumber": ""
    }
    wx.request({
      url: app.globalData.serverUrl,
      data: {
        "data": JSON.stringify(data),
        'act': "confirm_attendances"
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success: function (res) {
        console.log(res);
        wx.hideNavigationBarLoading()
        wx.hideLoading()
        if (res.data.status == 0) {
          wx.showToast({
            title: '操作成功',
            icon: 'none',
            duration: 1000,
            mask: true
          })
          if (that.data.active == 0) {
            that.queryData()
          } else {
            that.queryQituiData();
          }
        } else {
          wx.showToast({
            title: '操作失败',
            icon: 'none',
            duration: 1000,
            mask: true
          })
        }
      },
      fail: function (res) {
        wx.hideNavigationBarLoading()
        wx.hideLoading()
        wx.showToast({
          title: '撤回失败',
          icon: 'none',
          duration: 1000,
          mask: true
        })
      },
      complete: function (res) {
        wx.hideNavigationBarLoading()
        wx.hideLoading()
        console.log('submit complete');
      }
    })
  },






  //撤回
  setWithdraw: function (kididstr, status) {
    var that = this;
    var data = {
      "userid": app.globalData.userId,
      "schoolid": app.globalData.schoolId,
      "kididstr": kididstr,
      "status": status,
      "appType": app.globalData.appType,
      "appKey": app.globalData.appKey,
      "timeSpan": app.globalData.timespan,
      "mobileType": app.globalData.mobileType,
      "mobileSerialnumber": ""
    }
    wx.request({
      url: app.globalData.serverUrl,
      data: {
        "data": JSON.stringify(data),
        'act': "confirm_attendancesundo"
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success: function (res) {
        console.log(res);
        if (res.data.status == 0) {
          wx.showToast({
            title: '撤回成功',
            icon: 'none',
            duration: 1000,
            mask: true
          })
          if (that.data.active == 0) {
            that.queryData()
          } else {
            that.queryQituiData();
          }
        } else {
          wx.showToast({
            title: '撤回失败',
            icon: 'none',
            duration: 1000,
            mask: true
          })
        }
      },
      fail: function (res) {
        wx.showToast({
          title: '撤回失败',
          icon: 'none',
          duration: 1000,
          mask: true
        })
      },
      complete: function (res) {
        console.log('submit complete');
      }
    })
  },

  weiqiantuihandleClick: function (e) {
    //console.log("endTime - startTime = " + (this.endTime - this.startTime));   
    var index = e.currentTarget.dataset.index;
    var arr = this.data.attendanceKidListByMonthnoqiantui;
    var obj = this.data.attendanceKidListByMonthnoqiantui[index]
    if (obj.status == 0) {
      obj.status = 1
    } else {
      obj.status = 0
    }
    arr[index] = obj
    this.setData({
      attendanceKidListByMonthnoqiantui: arr
    })
    console.log("点击");

  },

  weiqiantuihandleLongPress: function (e) {
    //console.log("endTime - startTime = " + (this.endTime - this.startTime));
    var index = e.currentTarget.dataset.index;
    var relationship = this.data.attendanceKidListByMonthnoqiantui[index].relationshipList
    var nameList = [];
    var phone = [];
    for (var i = 0; i < relationship.length; i++) {
      nameList.push(relationship[i].name)
      phone.push(relationship[i].mobile)
    }
    wx.showActionSheet({
      itemList: nameList,
      success: function (res) {
        console.log(res.tapIndex)
        wx.makePhoneCall({
          phoneNumber: phone[res.tapIndex],
        })
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
    console.log("长按");
  },
 

  yiqiantuihandleLongPress: function (e) {
    var index = e.currentTarget.dataset.index;
    var arr = this.data.attendanceKidListByMonthyesqiantui;
    var obj = this.data.attendanceKidListByMonthyesqiantui[index]
    if (obj.status == 0) {
      obj.status = 1
    } else {
      obj.status = 0
    }
    arr[index] = obj
    this.setData({
      attendanceKidListByMonthyesqiantui: arr
    })
    console.log("长按");
  },
  queryData: function () {
    var that = this;
    var data = {
      "userid": app.globalData.userId,
      "schoolid": app.globalData.schoolId,
      "classid": that.data.classid,
      "date": that.data.selectdate,
      "appType": app.globalData.appType,
      "appKey": app.globalData.appKey,
      "timeSpan": app.globalData.timespan,
      "mobileType": app.globalData.mobileType,
      "mobileSerialnumber": ""
    }
    wx.request({
      url: app.globalData.serverUrl,
      data: {
        "data": JSON.stringify(data),
        'act': "get_kidattendanceinList"
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success: function (res) {
        console.log(res);
        if (res.data.status == 0) {

          var attendanceKidListByMonthno = res.data.AttendanceKidListByMonthno
          for (var i = 0; i < attendanceKidListByMonthno.length; i++) {
            attendanceKidListByMonthno[i].status = 0
          }
          var attendanceKidListByMonthyes = res.data.AttendanceKidListByMonthyes
          for (var i = 0; i < attendanceKidListByMonthyes.length; i++) {
            attendanceKidListByMonthyes[i].status = 0
          }

          that.setData({
            attendanceKidListByMonthno: attendanceKidListByMonthno,
            attendanceKidListByMonthyes: attendanceKidListByMonthyes,
            leaveListByMonthyes: res.data.LeaveListByMonthyes,
            allkidcount: res.data.allkidcount,
            inkidcount: res.data.inkidcount,
            leavecountno: res.data.leavecountno,
            leavekidcount: res.data.leavekidcount,
            weidaokidcount: res.data.weidaokidcount
          })
        }
      },
      fail: function (res) {},
      complete: function (res) {
        console.log('submit complete');
      }
    })
  },
  yiqiantuichehuiClick: function (e) {
    console.log(e);
    var that = this
    var arr = this.data.attendanceKidListByMonthyesqiantui;
    var kidStr = ""
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].status == 1) {
        kidStr += "," + arr[i].UserID
      }
    }
    if (kidStr.length > 0) {
      var status = 2
      kidStr = kidStr.substring(1)
      that.setWithdraw(kidStr, status)
    } else {
      wx.showToast({
        title: '请选择撤回的学生',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    }
  },

  queryQituiData: function () {
    var that = this;
    var data = {
      "userid": app.globalData.userId,
      "schoolid": app.globalData.schoolId,
      "classid": that.data.classid,
      "date": that.data.selectdateqiantui,
      "appType": app.globalData.appType,
      "appKey": app.globalData.appKey,
      "mobileType": app.globalData.mobileType,
      "timeSpan": app.globalData.timespan,
      "mobileSerialnumber": ""
    }
    wx.request({
      url: app.globalData.serverUrl,
      data: {
        "data": JSON.stringify(data),
        'act': "get_kidattendanceoutList"
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success: function (res) {
        console.log(res);
        if (res.data.status == 0) {
          var AttendanceKidListByMonthno = res.data.AttendanceKidListByMonthno
          for (var i = 0; i < AttendanceKidListByMonthno.length; i++) {
            AttendanceKidListByMonthno[i].status = 0
          }
          var AttendanceKidListByMonthyes = res.data.AttendanceKidListByMonthyes
          for (var i = 0; i < AttendanceKidListByMonthyes.length; i++) {
            AttendanceKidListByMonthyes[i].status = 0
          }
          that.setData({
            attendanceKidListByMonthnoqiantui: AttendanceKidListByMonthno,
            attendanceKidListByMonthyesqiantui: AttendanceKidListByMonthyes,
            leaveListByMonthyesqiantui: res.data.LeaveListByMonthyes,
            allkidcountqiantui: res.data.allkidCount,
            leavekidcountqiantui: res.data.leavekidcount,
            nooutkidCountqiantui: res.data.nooutkidCount,
            outkidCountqiantui: res.data.outkidCount
          })
        }
      },
      fail: function (res) {},
      complete: function (res) {
        console.log('submit complete');
      }
    })
  },

  bindDateChange: function (e) {
    console.log(e)
    this.setData({
      selectdate: e.detail.value
    })
    this.queryData();
  },


  getQiniuToken: function (e) {
    var that = this;
    var data = {
      "userid": app.globalData.userId,
      "schoolid": app.globalData.schoolId,
      "appType": app.globalData.appType,
      "appKey": app.globalData.appKey,
      "timeSpan": app.globalData.timespan
    }
    wx.request({
      url: app.globalData.serverQiNiuUrl,
      data: {
        "data": JSON.stringify(data)
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success: function (res) {
        console.log(res);
        if (res.data.status == 0) {
          that.setData({
            qiniuToken: res.data.data.token
          })
        } else {

        }
      },
      fail: function (res) {

      },
      complete: function (res) {
        console.log('submit complete');
      }
    })
  },




  bindDateQiantuiChange: function (e) {
    console.log(e)
    this.setData({
      selectdateqiantui: e.detail.value
    })
    this.queryQituiData();
  },
  btnQiantuiPreday: function () {
    var day = this.getDateStr(this.data.selectdateqiantui, -1);
    this.setData({
      selectdateqiantui: day
    })
    this.queryQituiData();
  },

  btnQiantuiNextday: function () {
    if (this.data.selectdateqiantui < this.data.currentdate) {
      var day = this.getDateStr(this.data.selectdateqiantui, 1);
      this.setData({
        selectdateqiantui: day
      })
      this.queryQituiData();
    } else {
      wx.showToast({
        title: '还未到达明天',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    }
  },
  getDateStr: function (today, addDayCount) {
    var dd;
    if (today) {
      dd = new Date(today);
    } else {
      dd = new Date();
    }
    dd.setDate(dd.getDate() + addDayCount); //获取AddDayCount天后的日期 
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1; //获取当前月份的日期 
    var d = dd.getDate();
    if (m < 10) {
      m = '0' + m;
    }
    if (d < 10) {
      d = '0' + d;
    };
    return y + "-" + m + "-" + d;
  },

  btnPreday: function () {
    var day = this.getDateStr(this.data.selectdate, -1);
    this.setData({
      selectdate: day
    })
    this.queryData();
  },

  btnNextday: function () {
    if (this.data.selectdate < this.data.currentdate) {
      var day = this.getDateStr(this.data.selectdate, 1);
      this.setData({
        selectdate: day
      })
      this.queryData();
    } else {
      wx.showToast({
        title: '还未到达明天',
        icon: 'none',
        duration: 1000,
        mask: true
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.active == 0) {
      this.queryData()
    } else {
      this.queryQituiData();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})